/**
 * 
 */
package com.googlecode.easyibatis.core.utils;

import org.apache.commons.lang.StringUtils;

/**
 * @author wuyu
 * 
 */
public class Sort {
	public static final String ASC = "asc";
	public static final String DESC = "desc";

	/**
	 * 默认构造式，使用ASC做为排序方式
	 * 
	 * @param propertyName
	 */
	public Sort(String propertyName) {
		this.propertyName = propertyName;
		this.sortType = ASC;
	}

	/**
	 * @param propertyName
	 * @param sortType
	 */
	public Sort(String propertyName, boolean asc) {
		this.propertyName = propertyName;
		this.sortType = asc ? ASC : DESC;
	}

	/**
	 * 
	 * overriding methods (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return StringUtils.isBlank(propertyName) ? StringUtils.EMPTY : String.format("%s %s", propertyName, sortType);
	}

	/**
	 * 排序字段
	 */
	private String propertyName;
	/**
	 * 排序方式
	 */
	private String sortType = ASC;

	/**
	 * @return the propertyName
	 */
	public String getPropertyName() {
		return propertyName;
	}

	/**
	 * @param propertyName
	 *            the propertyName to set
	 */
	public void setPropertyName(String propertyName) {
		this.propertyName = propertyName;
	}

	/**
	 * @return the sortType
	 */
	public String getSortType() {
		return sortType;
	}

	/**
	 * @param sortType
	 *            the sortType to set
	 */
	public void setSortType(String sortType) {
		this.sortType = sortType;
	}

}
